<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<?php

DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'root');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'irrealworlds');
error_reporting(E_ALL);
ini_set('display_errors', '1');

	
$dbc;


/**
 * Connects to db
 *
 */
function connect(){
	global $dbc;
	$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die
	('Could not connect to MySQL: '.mysqli_connect_error() );
	
	return $dbc;
}

/**
 *Disconnects from db
 * 
 */
function disconnect(){
	global $dbc;
	if (mysqli_close($dbc) != 0) {
		return 1;
	}  else {
		return 0;
	}
}

function makeQuery($query){
	global $dbc;
	
	$result = mysqli_query($dbc, $query);
	
	/*
	if (preg_match("/select/i",$query)) {
		
	}
	
	if (preg_match("/update/i",$query)) {
		
	}
	
	if (preg_match("/insert/i",$query)) {
		
	}
	
	if (preg_match("/delete/i",$query)) {
		
	} */
	
	return $result;
}

/**
 * 
 * select all from table
 */

function selectAllFrom($table_name){
	$query = 'select * from '.$table_name;
	return makeQuery($query);
}

/**
 * 
 * Deletes entry from table
 * @param $name name of entry
 * @param $table name of table
 */
function deleteFromTable($name, $table){
	$query = 'delete '.$name.' from '.$table;
}


function getDBC(){
	global $dbc;
	return $dbc;
}

/**
 * 
 * Updates ressources 
 * @param $townid

function updateResourcesOfId($townid){
	global $dbc;
	mysqli_query($dbc, "UPDATE last_activity (townid) VALUES ('$townid')");
	
}
 */


